package com.cdu.guoxinan.www.smartcom.service.impl;

import com.cdu.guoxinan.www.smartcom.domian.dto.ComplaintDTO;
import com.cdu.guoxinan.www.smartcom.domian.dto.QueryCompDTO;
import com.cdu.guoxinan.www.smartcom.domian.pojo.Complaint;
import com.cdu.guoxinan.www.smartcom.domian.vo.ComplaintVO;
import com.cdu.guoxinan.www.smartcom.mapper.ComplaintMapper;
import com.cdu.guoxinan.www.smartcom.service.ComplaintService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service
public class ComplaintServiceImpl implements ComplaintService {

    @Resource
    private ComplaintMapper complaintMapper;

    /**
     * 分页查询投诉信息（支持条件筛选）
     */
    @Override
    public PageInfo<ComplaintVO> getAllComplaints(QueryCompDTO queryCompDTO) {
        PageHelper.startPage( queryCompDTO.getPage(), queryCompDTO.getLimit());
        List<ComplaintVO> complaints = complaintMapper.getAllComplaints(queryCompDTO);
        return new PageInfo<>(complaints);
    }

    /**
     * 更新投诉信息
     */
    @Override
    public boolean add(ComplaintDTO complaint) {


        return complaintMapper.add( complaint)>0;
    }

    @Override
    public boolean update(Complaint complaint) {
        int result = complaintMapper.update(complaint);
        return result>0;
    }

    /**
     * 删除投诉信息
     */
    @Override
    public boolean delete(Long complaintId) {
        return complaintMapper.delete(complaintId)>0;
    }

    @Override
    public PageInfo<ComplaintVO> getAllById(Long residentId) {
        PageHelper.startPage( 1,10);
        List<ComplaintVO> complaints = complaintMapper.getAllById(residentId);
        return new PageInfo<>(complaints);

    }
}
